#!/bin/bash
#  Installs various external dependencies required to generate a sample application with 
#  the  latest version of Catalyst::Example::InstantCrud (the head from the I::C svn repo, which is more up to date 
#  than what is on CPAN.
#
#  Future plans are to install a simple Catalyst demo appplication (or better yet, several of them), and run them, at one shot.
#
#  This script takes a long take -- I estimate two or three hours.
#  Running it involves a significant amount of babysitting, because there are various places that require user input.
#  That said, a lot of effort has already gone into automating as much of the installation as possible.
#
#  Where I couldn't (yet) figure out how to do this, I have tried to always print a message giving very explicit advice on what to do.
#
#  Usually the advice is to accept the next set of defaults until advised otherwise.
#  If I can recall correctly, one exception to this occurs when configuring CPAN -- at some point here you have to choose "no"
#  for the rest of the script to run smoothly, whereas the default is "yes."
#
#  The idea is for users with relatively little experience in Catalyst/Perl to be able to run this script
#  without any guesswork (eg, "do I take the default and install module such and so, or not?), and wind up with 
#  a sane environment for experimenting with catalyst.
#
#  My eventual goal is to rework this script to run completely unattended.
#
#  Tip: to ensure that this install scripts doesn't stop working if, eg, the ssh connection is interrupted
#  you can run this from within a screen session, 
#  using the gnu screen utility, installed by default on most unices.
#  See GNU Screen: an introduction and beginner's tutorial
#  http://www.kuro5hin.org/story/2004/3/9/16838/14935 


. ../environment/environment.sh;
. ./functions.sh

mkdir_wrapper $EXTERNAL_DEPENDENCIES_TOP

# Local Perl
localperlfile=$LOCALPERL/bin/perl
currentperl=`which perl`
if [[ ! $localperlfile == $currentperl ]];
  then
    echo "perl not installed at $localperlfile"
    echo "installing it now....."
    LOCALPERL_BUILD=$EXTERNAL_DEPENDENCIES/localperl_build
    mkdir_wrapper $LOCALPERL_BUILD
    install_dir=`pwd`
    pushd $LOCALPERL_BUILD
      $install_dir/install-local-perl.sh $LOCALPERL
    popd
    backup_external_deps perlbuilt
else 
  echo "local perl installed at $localperlfile"
  echo "skipping local perl install"
fi

install_hard_cpan_mod CPAN::Config  './cpan-config.sh' cpanconfig_installed
install_hard_cpan_mod Module::Build './module-build.sh' modulebuild_installed

# shadowcat installer -- should have less user interaction
# can I get this to work?
install_hard_cpan_mod Catalyst \
                      './shadowcat-catalyst-installer.sh' catalyst_installed
#install_hard_cpan_mod Catalyst \
#                      'perl ./catalyst.pl' catalyst_installed

# this next bit digests tons of mods, pulling from ModuleList.pm
# just set the first arg to whatever hasn't been installed yet
install_hard_cpan_mod DBIx::Class::DigestColumns 'perl ./cpan-mods.pl' misc_cpan_mods_installed

install_hard_cpan_mod Catalyst::Plugin::HTML::Widget \
                      'perl ./catalyst-plugin-html-widget.pl' htmlwidget_installed

# InstantCrud Checkout
pmc_svn_checkout $SVN_CHECKOUTS $SVN_CHECKOUTS/Catalyst-Example-InstantCRUD http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Example-InstantCRUD instantcrud_co

#Catalyst Tutorial Checkout
pmc_svn_checkout $SVN_CHECKOUTS $SVN_CHECKOUTS/Tutorial http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/ catalyst_tutorial_co


